package main

import "fmt"

type Address struct {
	Name string
	Phone int
}

func main() {
	var userinfo = make(map[string]interface{})
	userinfo["username"] = "张三"
	userinfo["age"] = 25
	userinfo["hobby"] = []string{"看书", "唱歌"}
	fmt.Println(userinfo)
	fmt.Println(userinfo["username"])
	fmt.Println(userinfo["age"])
	fmt.Println(userinfo["hobby"]) // 空接口不支持索引

	var address = Address{
		Name: "李四",
		Phone: 123456789,
	}
	userinfo["address"] = address
	fmt.Println(address.Name)
	fmt.Println(userinfo["address"].(Address).Phone)  // 结构体输出

	// 类型断言
	hobby2, _ := userinfo["hobby"].([]string) 

	fmt.Println(hobby2[1]) // 索引切片输出

	address2, _ :=  userinfo["address"].(Address)
	fmt.Println(address2.Name, address2.Phone) // 结构体输出
}